package com.yk.faceapplication.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.allinpay.xed.R;
import com.yk.faceapplication.callback.UpdateBillStatusCallback;
import com.yk.faceapplication.entity.Bill;
import com.yk.faceapplication.entity.Card;
import com.yk.faceapplication.util.FormatUtil;
import com.yk.faceapplication.util.ImageUtil;

import java.util.List;


public class CardAdapter extends BaseAdapter {
	private Context context = null;
	private List<Card> list = null;

	public CardAdapter(Context context, List<Card> list) {
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		if (list != null) return list.size();
		return 0;
	}

	@Override
	public Object getItem(int position) {
		if (list != null) list.get(position);
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.item_card, null);
			viewHolder.logoIV = (ImageView) convertView.findViewById(R.id.logo_img);
			viewHolder.nameTV = (TextView) convertView.findViewById(R.id.name_tv);
			viewHolder.cardNumTV = (TextView) convertView.findViewById(R.id.card_last_num_tv);
			viewHolder.cardTypeTV = (TextView) convertView.findViewById(R.id.name_type_tv);

			convertView.setTag(viewHolder);
		}
		else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
//ImageUtil.displayImage(context,list.get(position).get);
		viewHolder.cardTypeTV.setText(list.get(position).getType() == 0?"借记卡":"信用卡");
		viewHolder.nameTV.setText(list.get(position).getBankName());
		viewHolder.cardNumTV.setText(list.get(position).getCreditCardNo().subSequence(list.get(position).getCreditCardNo().length()-4,list.get(position).getCreditCardNo().length()));

		return convertView;
	}

	class ViewHolder {
		private ImageView logoIV = null;
		private TextView nameTV = null;
		private TextView cardNumTV = null;
		private TextView cardTypeTV = null;

	}

}
